package com.pms.init;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.espirit.eap.manager.ModelBuilderSupport;
import com.espirit.eap.pagelayout.Element;
import com.espirit.eap.pagelayout.ModelField;
import com.pms.manager.DebitChargeItemStandard;

@Component
public class DebitChargeItemStandardBuilder extends ModelBuilderSupport {

	static final String NAME = "name";
	static final String REMARK = "remark";
	static final String DEBITCHARGEITEM = "debitChargeItem";
	static final String GARDENIDS = "gardenIds";
	static final String BUILDINGIDS = "buildingIds";
	static final String HOUSECODES = "houseCodes";
		
	
	@Override
	public boolean init() {
		return super.setClass(DebitChargeItemStandard.class, "Debig Charge Item Standard", "收费标准");
	}

	@Override
	public void buildFields() {
		addModelField(NAME, "Name", "名称");
		addModelField(REMARK, "Remark", "说明");
		addModelField(DEBITCHARGEITEM, "Charge Item", "收费项目");
		addModelField(GARDENIDS, "Gardens", "花园");
		addModelField(BUILDINGIDS, "Buildings", "楼宇");
		addModelField(HOUSECODES, "Houses", "房屋编码");
	}
	
	@Override
	public void prepareLayoutElements() {
		super.prepareLayoutElements();
	}
	
	
	@Override
	protected void setDefaultLayoutButtons() {
		super.setDefaultLayoutButtons();
	}
	
	@Override
	protected void addSearchFields() {
		super.addSearchField(convertPropertyToField(DEBITCHARGEITEM, NAME));
	}
	
	@Override
	protected void addListFields() {
		addListField(convertPropertyToField(DEBITCHARGEITEM, NAME, REMARK));
	}
	
	@Override
	protected void addDetailFields() {
		addDetailField(convertPropertyToField(DEBITCHARGEITEM, NAME, GARDENIDS, BUILDINGIDS, HOUSECODES, REMARK));
	}
	
	@Override
	protected Element convertFieldToElement(ModelField mf, boolean isListLayout) {
		Element element = super.convertFieldToElement(mf, isListLayout);
		if (!isListLayout){
			if (GARDENIDS.equals(element.getName())){
				setElementTreebox(element, "fn.service('pms.house.garden').allGardens");
			} else if (BUILDINGIDS.equals(element.getName())){
				setElementTreebox(element, "fn.service('pms.house.building').allBuildings");
			} else if (HOUSECODES.equals(element.getName())){
				element.setTagName("textarea");
			}
		}
		return element;
	}
	
	@Override
	protected void gatherExproperties() {
		exProperties.put(REQUIRED, new String[]{DEBITCHARGEITEM, NAME});
	}
}
